package com.situ.cookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/cookie2")
public class Cookie2 extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("Cookie2.service()");
		
		Cookie[] cookies = req.getCookies();
		
		
		if (cookies != null) { // 防止误操作   直接访问 cookie2      浏览器里没cookie值
			for (Cookie cookie : cookies) {
				System.out.println(cookie.getValue()+": "+cookie.getName());
			}
		}	
		
	}
}
